/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package x.test;

/**
 *
 * @author eros
 */
import java.awt.print.PrinterJob;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.PrintServiceAttribute;
import javax.print.attribute.standard.PrinterName;

public class SimplePrint {

   public static void main(String[] args) {

       try {

           PrintService psZebra = null;
           String sPrinterName = null;
           PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);

           for (int i = 0; i < services.length; i++) {

               PrintServiceAttribute attr = services[i].getAttribute(PrinterName.class);
               sPrinterName = ((PrinterName) attr).getValue();

               if (sPrinterName.toLowerCase().indexOf("generic") >= 0) {
                   psZebra = services[i];
                   break;
               }
           }

           if (psZebra == null) {
               System.out.println("Zebra printer is not found.");
               return;
           }
           psZebra = getPrintService("generic");
           DocPrintJob job = psZebra.createPrintJob();
          

           String s ="FK"
+"FN"
+"N"
+"I8,A,003"
+"q824"
+"R5,5"
+"S2"
+"D24"
+"ZT"
+"N"
+"A300,370,4,1,1,1,N,'17/03/2010 18:16:10  TM'"
+"A320,245,5,1,1,1,N,''"
+"A300,350,4,1,1,1,N,'39a2m10d Masc '"
+"A390,338,4,1,1,1,N,''"
+"A520,20,5,2,1,1,N,'TTT-UNIDADE TESTE ''"
+"A500,20,5,2,1,1,N,'000001-POSTO 01 TESTE YYYY''"
+"A300,22,4,1,1,1,N,'SORO'"
+"A300,37,4,1,1,1,N,'TUBO AMARELO'"
+"A49,225,3,1,1,1,N,''"
+"B479,50,5,2,2,6,85,N,'020535835915'"
+"A393,100,5,1,1,1,N,'020535835915-500423115893'"
+"A380,140,5,1,1,1,N,'1026464539'"
+"A368,56,5,1,1,1,N,'TESTE ADRIANO BALA'"
+"A60,210,0,1,1,1,N,''"
+"A348,50,5,1,1,1,N,' TGO TGO'"
+"A300,2,4,2,1,1,R,'7755923 BIO YYYYY'"
+"P1"
+"FE";

           //char[] by = s.getChars(0, s.length(), null, );
           //byte[] by = s.getBytes();
           char[] by = s.toCharArray();
               DocFlavor flavor = DocFlavor.CHAR_ARRAY.TEXT_PLAIN;// DocFlavor.INPUT_STREAM.AUTOSENSE;//DocFlavor.STRING.TEXT_PLAIN;//DocFlavor.BYTE_ARRAY.AUTOSENSE;
           Doc doc = new SimpleDoc(s.toCharArray(), flavor, null);
           job.print(doc, null);
           System.out.println(doc.toString());

       } catch (PrintException e) {
           e.printStackTrace();
       }
   }



   public static PrintService getPrintService(String name){
        PrintService psZebra = null;
           String sPrinterName = null;
           PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);

           for (int i = 0; i < services.length; i++) {

               PrintServiceAttribute attr = services[i].getAttribute(PrinterName.class);
               sPrinterName = ((PrinterName) attr).getValue();

               if (sPrinterName.toLowerCase().indexOf(name) >= 0) {
                   psZebra = services[i];
                   break;
               }
           }
           if(psZebra == null){
               System.out.println("No service found...");
           }
           return  psZebra;
   }

}